package com.proposition.exam.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.proposition.commons.exam.result.Result;
import com.proposition.commons.exam.result.ResultUtil;
import com.proposition.commons.exam.util.ExamAddUtil;
import com.proposition.commons.exam.util.ExamFieldVolidateUtil;
import com.proposition.commons.exam.util.ExamUtil;
import com.proposition.commons.model.ExamAcupointAdult;
import com.proposition.commons.model.ExamAcupointAdultOriginal;
import com.proposition.exam.mapper.ExamAcupointAdultMapper;
import com.proposition.exam.service.ExamAcupointAdultService;
import com.proposition.support.security.CurrentUser;
import com.proposition.support.utils.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: 陈玉林
 * @modifiedBy:
 * @date: Create In 14:19 2017/11/2
 * @description:问答题-腧穴试题服务类接口实现类
 */
@Service
public class ExamintAcupointAdultServiceImpl extends ServiceImpl<ExamAcupointAdultMapper, ExamAcupointAdult> implements ExamAcupointAdultService {


	@Autowired
	private ExamAcupointAdultMapper examAcupointAdultMapper;

    @Transactional
    @Override
    public Result add(String[] answerXWDW, Float[] answerXWDWScore, ExamAcupointAdult exam, ExamAcupointAdultOriginal examOriginal) {
        String stem = ExamFieldVolidateUtil.getIllegalStem(exam.getStem());
        exam.setStem(stem);
        ExamAddUtil.volidateUniqueStem(exam);
        ExamUtil.volidateOutlineCode(exam.getOutlineCode());

        String categoryStr = ExamUtil.getCategoryStr(exam.getCategoryId());
        String id = UUIDUtil.getExamUUIDByCategory(categoryStr);
        String userIdImport = CurrentUser.INSTANCE.getUserId();
        Object[] examArr=ExamUtil.setAnswerXWDW(exam,examOriginal,answerXWDW,answerXWDWScore);
        exam = (ExamAcupointAdult) examArr[0];
        examOriginal = (ExamAcupointAdultOriginal) examArr[1];

        exam.setId(id);//设置id
        exam.setUserIdImport(userIdImport);//设置当前导入用户id
        exam.insert();

        examOriginal.setId(id);
        examOriginal.setUserIdImport(userIdImport);
        examOriginal.insert();

        return ResultUtil.sucess();
    }

	@Override
	public ExamAcupointAdult selectExamAcupointAdultById(String id) {
		return examAcupointAdultMapper.selectExamAcupointAdultById(id);
	}

}
